package com.ruoyi.app.controller;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.app.service.IShopInfoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.app.domain.RestockProduct;
import com.ruoyi.app.service.IRestockProductService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 进货单商品Controller
 * 
 * @author ruoyi
 * @date 2024-12-12
 */
@RestController
@RequestMapping("/restock/restockProduct")
public class RestockProductController extends BaseController
{
    @Autowired
    private IRestockProductService restockProductService;

    /**
     * 查询进货单商品列表
     */
    @PreAuthorize("@ss.hasPermi('restock:restockProduct:list')")
    @GetMapping("/list")
    public TableDataInfo list(RestockProduct restockProduct)
    {
        startPage();
        List<RestockProduct> list = restockProductService.selectRestockProductList(restockProduct);
        return getDataTable(list);
    }

    /**
     * 导出进货单商品列表
     */
    @PreAuthorize("@ss.hasPermi('restock:restockProduct:export')")
    @Log(title = "进货单商品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RestockProduct restockProduct)
    {
        List<RestockProduct> list = restockProductService.selectRestockProductList(restockProduct);
        ExcelUtil<RestockProduct> util = new ExcelUtil<RestockProduct>(RestockProduct.class);
        util.exportExcel(response, list, "进货单商品数据");
    }

    /**
     * 获取进货单商品详细信息
     */
    @PreAuthorize("@ss.hasPermi('restock:restockProduct:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(restockProductService.selectRestockProductById(id));
    }

    /**
     * 新增进货单商品
     */
    @PreAuthorize("@ss.hasPermi('restock:restockProduct:add')")
    @Log(title = "进货单商品", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody RestockProduct restockProduct)
    {
        return toAjax(restockProductService.save(restockProduct));
    }

    /**
     * 修改进货单商品
     */
    @PreAuthorize("@ss.hasPermi('restock:restockProduct:edit')")
    @Log(title = "进货单商品", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody RestockProduct restockProduct)
    {
        return toAjax(restockProductService.updateById(restockProduct));
    }

    /**
     * 删除进货单商品
     */
    @PreAuthorize("@ss.hasPermi('restock:restockProduct:remove')")
    @Log(title = "进货单商品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        List<String> objects = Arrays.asList(ids);
        return toAjax(restockProductService.removeByIds(objects));
    }
}
